//
//  QRReceiptVC.swift
//  RPay
//
//  Created by Charlie Liao on 2017/7/5.
//  Copyright © 2017年 Charlie. All rights reserved.
//

import UIKit

class QRReceiptVC: Pay_ReceiptVC {
    
    // MARK: - Life Cycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = LocalStr("收款")
        discriptionLabel.text = LocalStr("扫一扫上面的二维码，向我付款")
                setBtn.setTitle(LocalStr("设置金额"), for: .normal)
        // Do any additional setup after loading the view.
        生成二维码()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController!.setNavigationBarHidden(false, animated: animated)
    }
    
    // MARK: - Event respond
    /// 点击设置金额按钮
    override func tapSetAmountBtn() {
        let vc = SetupAmountVC()
        vc.amount = amount
        vc.didSetupAmount = {(amount) in
            self.amount = amount
        }
        navigationController!.pushViewController(vc, animated: true)
    }
    
    // MARK: - Private
    
    private func 生成二维码() {
        let userName = UserShare.shared.loginUser!.userName
        let money = String(format: "%.2f", amount)
        
        let timestamp = NSDate.nowTimestamp
        let type = kApiParamTransferTypeReceive
        let codestr = "\(userName)|\(money)|\(timestamp)|\(type)"
        self.QRcodeImgView.image = codestr.generateQRCodeWithLogo(logo: #imageLiteral(resourceName: "icon_denglu_logo"))
    }
    
    // MARK: - Get
    var amount: Float = 0 {
        didSet {
            生成二维码()
        }
    }
}
